from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import time
import os

class TestMoudle:
    device = ''
    sn = ''
    def __init__(self,sn):
        self.device = MonkeyRunner.waitForConnection(5.0,sn)
	self.sn = sn

    def printToFile(self,content):
	filePath = 'd:/' + self.sn + '.txt'
        f = open(filePath, 'a')
        print >>f,content
        f.close

    def printLog(self,content):
        content1 = str(time.strftime("%H:%M:%S")) + '  '+ content
        print content1
        self.printToFile(content1)
        
    def soundRecorder(self,numTotal):
        self.printLog('SoundRecorder Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.soundrecorder/.SoundRecorder')
            time.sleep(2)
            self.device.touch(443,564,MonkeyDevice.DOWN_AND_UP)
            time.sleep(3)
            self.device.touch(584,570,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(787,367,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
	    adbCommandRM = 'adb -s ' + self.sn + ' shell rm /mnt/sdcard/*.3gpp'
            os.system(adbCommandRM)
            content ='SoundRecorder Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
            #self.easyDevice.touch(By.id('id/recordButton'), 'downAndUp')
            '''
            text = self.easyDevice.getText(By.id('id/timerView'))
            result = cmp(text,'00:00:05')
            while result < 0:   
                text = self.easyDevice.getText(By.id('id/timerView'))
                result = cmp(text,'00:00:05')
            else:
                self.easyDevice.touch(By.id('id/stopButton'), 'downAndUp')
                self.easyDevice.touch(By.id('id/acceptButton'), 'downAndUp')
                self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
                content ='SoundRecorder Test ' + str(numCurrent)
                self.printLog(content)
                numCurrent = numCurrent + 1;
                time.sleep(10)
                numTotal = numTotal - 1
            '''
        else:
            self.printLog('SoundRecorder Test Complete')

    def dvd(self,numTotal):
        self.printLog('DVD Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.jensor.multimedia/.activity.DvdActivity')
            time.sleep(15)
            self.device.touch(875,277,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(693,590,MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.touch(806,594,MonkeyDevice.DOWN_AND_UP)
            time.sleep(15)
            self.device.touch(875,277,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(578,588,MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.touch(806,594,MonkeyDevice.DOWN_AND_UP)
            time.sleep(15)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'DVD Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('DVD Test Complete')

    def radio(self,numTotal):
        self.printLog('Radio Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.fmradiojc/.RadioActivity')
            time.sleep(3)
            self.device.touch(858,516,MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/btnBackward'), 'downAndUp')
            time.sleep(3)
            self.device.touch(859,200,MonkeyDevice.DOWN_AND_UP)
            time.sleep(25)
            self.device.touch(642,531,MonkeyDevice.DOWN_AND_UP)
            time.sleep(25)
            self.device.touch(642,531,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/btnBackward'), 'downAndUp')
            content = 'Radio Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Radio Test Complete')

    def bt(self,numTotal):
        self.printLog('BT Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.bluetoothphone/.MainActivity')
            time.sleep(2)
            self.device.touch(925,441,MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/btnBluetooth'), 'downAndUp')
            time.sleep(3)
            self.device.touch(925,441,MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/btnBluetooth'), 'downAndUp')
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'BT Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('BT Test Complete')

    def wifi(self,numTotal):
        self.printLog('Wifi Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.settings/.Settings')
            time.sleep(2)
            self.device.touch(939,239,MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/switchWidget'), 'downAndUp')
            time.sleep(5)
            self.device.touch(939,239,MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/switchWidget'), 'downAndUp')
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'Wifi Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Wifi Test Complete')

    def navigation(self,numTotal):
        self.printLog('Navigation Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.jensor.navigation/.JensorChooserActivity')
            time.sleep(5)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            content = 'Navigation Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Navigation Test Complete')

    def keylearning(self,numTotal):
        self.printLog('KeyLearning Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.keymemory/.WelcomeActivity')
            time.sleep(2)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/exit'), 'downAndUp')
            content = 'KeyLearning Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('KeyLearning Test Complete')

    def equalizer(self,numTotal):
        self.printLog('Equalizer Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.jensor.soundeffect/.activity.SoundEffectActivity')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'Equalizer Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Equalizer Test Complete')

    def videostudio(self,numTotal):
        self.printLog('VideoStudio Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.videoeditor/.ProjectsActivity')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'VideoStudio Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('VideoStudio Test Complete')

    def calculator(self,numTotal):
        self.printLog('Calculator Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.calculator2/.Calculator')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'Calculator Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Calculator Test Complete')

    def calender(self,numTotal):
        self.printLog('Calender Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.calendar/.AllInOneActivity')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'Calender Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Calender Test Complete')

    def clock(self,numTotal):
        self.printLog('Clock Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.deskclock/.DeskClock')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'Clock Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Clock Test Complete')

    def Apkinstaller(self,numTotal):
        self.printLog('Apkinstaller Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.apkinstaller/.apkinstaller')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Apkinstaller Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Apkinstaller Test Complete')

    def Browser(self,numTotal):
        self.printLog('Browser Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
	    self.device.type('http://192.168.10.101:8080')
            #self.easyDevice.type(By.id('id/url'), 'www.baidu.com')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Browser Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1           
            numTotal = numTotal - 1
        else:
            self.printLog('Browser Test Complete')

    def ES(self,numTotal):
        self.printLog('ES Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.estrongs.android.pop/.view.FileExplorerActivity')
            time.sleep(3)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'ES Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('ES Test Complete')

    def FishGame(self,numTotal):
        self.printLog('FishGame Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='org.cocos2dx.FishingJoy2/.FishingJoy2')
            time.sleep(20)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'FishGame Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('FishGame Test Complete')

    def Gallery3d(self,numTotal):
        self.printLog('Gallery3d Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.gallery3d/.app.Gallery')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Gallery3d Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Gallery3d Test Complete')

    def Iceworld(self,numTotal):
        self.printLog('Iceworld Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.carrot.iceworld/.CarrotFantasy')
            time.sleep(20)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Iceworld Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Iceworld Test Complete')

    def Quicksearchbox(self,numTotal):
        self.printLog('Quicksearchbox Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.quicksearchbox/.SearchActivity')
            time.sleep(2)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Quicksearchbox Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Quicksearchbox Test Complete')

    def Smart(self,numTotal):
        self.printLog('Smart Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.storm.smart/.LogoActivity')
            time.sleep(5)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Smart Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Smart Test Complete')

    def Videoout(self,numTotal):
        self.printLog('Videoout Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.videoout/.AUXActivity')
            time.sleep(2)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/btn_exit'),MonkeyDevice.DOWN_AND_UP)
            #self.device.touch(906.0,522.0,'DOWN_AND_UP')
            #self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Videoout Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Videoout Test Complete')

    def Browser1M(self,numTotal):
        self.printLog('Browser1M Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/1m.zip')
            #self.easyDevice.type(By.id('id/url'), 'http://192.168.1.56:8080/1m.zip')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(3)
            self.device.startActivity(component='com.android.providers.downloads.ui/.DownloadList')
            time.sleep(60)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
	    adbCommandRM = 'adb -s ' + self.sn + ' shell rm /mnt/sdcard/download/1m*.zip'
            os.system(adbCommandRM)
            content = 'Browser1M Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('Browser1M Test Complete')

    def Browser50M(self,numTotal):
        self.printLog('Browser50M Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/50m.zip')
            #self.easyDevice.type(By.id('id/url'), 'http://192.168.1.56:8080/50m.zip')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
	    self.device.startActivity(component='com.android.providers.downloads.ui/.DownloadList')
	    time.sleep(180)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
	    adbCommandRM = 'adb -s ' + self.sn + ' shell rm /mnt/sdcard/download/50m*.zip'
            os.system(adbCommandRM)
            content = 'Browser50M Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('Browser50M Test Complete')

    def Music(self,numTotal):
        self.printLog('Music Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/music.mp3')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.touch(517,242,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(642,531,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Music Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(2)
            numTotal = numTotal - 1
        else:
            self.printLog('Music Test Complete')

    def Picture(self,numTotal):
        self.printLog('Picture Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/pic.png')
            #self.easyDevice.type(By.id('id/url'), 'http://192.168.1.56:8080/pic.png')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Picture Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(2)
            numTotal = numTotal - 1
        else:
            self.printLog('Picture Test Complete')

    def Video(self,numTotal):
        self.printLog('Video Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/video.mp4')
            #self.easyDevice.type(By.id('id/url'), 'http://192.168.1.56:8080/video.mp4')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.touch(686,258,MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.touch(657,575,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Video Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(2)
            numTotal = numTotal - 1
        else:
            self.printLog('Video Test Complete')

    def Cheyooh(self,numTotal):
        self.printLog('Cheyooh Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.cheyooh/.activity.LoadingActivity')
            time.sleep(20)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Cheyooh Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Cheyooh Test Complete')

    def Dazhihui(self,numTotal):
        self.printLog('Dazhihui Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.dazhihui.gpad/.dzh')
            time.sleep(5)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.touch(630,338, MonkeyDevice.DOWN_AND_UP)
            content = 'Dazhihui Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('Dazhihui Test Complete')

    def Dianping(self,numTotal):
        self.printLog('Dianping Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.dianping.v1/.SplashScreenActivity')
            time.sleep(10)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Dianping Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('Dianping Test Complete')

    def musicplayer(self,numTotal):
        self.printLog('MusicPlayer Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.music/.MusicBrowserActivity')
            time.sleep(5)
            self.device.touch(505,93, MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/songtab'), 'downAndUp')
            time.sleep(5)
            self.device.touch(396,163, MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.touch(509,524, MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/pause'), 'downAndUp')
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'MusicPlayer Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('MusicPlayer Test Complete')

    def WangYi(self,numTotal):
        self.printLog('WangYi NEWS Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.netease.newsreader.activity/com.netease.nr.biz.ad.AdActivity')
            time.sleep(15)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'WangYi NEWS Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('WangYi NEWS Test Complete')

    def Oupeng(self,numTotal):
        self.printLog('Oupeng Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.oupeng.mini.android/com.opera.mini.android.Browser')
            time.sleep(20)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Oupeng Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('Oupeng Test Complete')

    def tingshu(self,numTotal):
        self.printLog('Tingshu Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='bubei.tingshu/.ui.LOGOActivity')
            time.sleep(5)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Tingshu Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Tingshu Test Complete')

    def VedioPlayer(self,numTotal):
        self.printLog('VedioPlayer Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='android.rk.RockVideoPlayer/.RockVideoPlayer')
            time.sleep(3)
            self.device.touch(428,114, MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/video_name'), 'downAndUp')
            time.sleep(20)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(3)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'VedioPlayer Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('VedioPlayer Test Complete')

    def Fruit(self,numTotal):
        self.printLog('Fruit Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component = 'com.halfbrick.fruitninja/com.halfbrick.mortar.MortarGameActivity')
            time.sleep(20)
            self.device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            content = 'Fruit Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Fruit Test Complete')

    def sendEmail(self,numTotal):
        self.printLog('SendEmail Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.email/.activity.Welcome')
            time.sleep(5)
            self.device.touch(788,89, MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.type('jensortest@163.com')
            time.sleep(1)
            self.device.touch(310,261, MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.type('Test')
            time.sleep(1)
            self.device.touch(276,291, MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.type('Test')
            time.sleep(1)
            self.device.touch(766,91, MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'SendEmail Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('SendEmail Test Complete')

    def checkEmail(self,numTotal):
        self.printLog('CheckEmail Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.email/.activity.Welcome')
            time.sleep(5)
            self.device.touch(428,171, MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'CheckEmail Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('CheckEmail Test Complete')

    def contact(self,numTotal):
        self.printLog('Contact Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.contacts/.activities.PeopleActivity')
            time.sleep(5)
            self.device.touch(859,103, MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/create_contact_button'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.device.type('Test')
            time.sleep(1)
            self.device.touch(58,97, MonkeyDevice.DOWN_AND_UP)
            #self.easyDevice.touch(By.id('id/icon'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.touch(1002,91, MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(921,202, MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(635,358, MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Contact Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Contact Test Complete')

    def btCall(self,numTotal):
        self.printLog('BTCall Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.bluetoothphone/.MainActivity')
            time.sleep(5)
            self.device.type('10000')
            time.sleep(2)
            self.easyDevice.touch(By.id('id/btnPhone'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.easyDevice.touch(By.id('id/phonecall_hang_up'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(5)
            self.easyDevice.touch(By.id('id/btnQuit'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(10)
            content = 'BTCall Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('BTCall Test Complete')

    def btMusic(self,numTotal):
        self.printLog('BTMusic Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.bluetoothphone/.BluetoothMusicActivity')
            time.sleep(5)
            self.easyDevice.touch(By.id('id/music_btn_play'),MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(10)
            content = 'BTMusic Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('BTMusic Test Complete')

    def Weixin(self,numTotal):
        self.printLog('Weixin Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.tencent.mm/.ui.LauncherUI')
            time.sleep(20)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            content = 'Weixin Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('Weixin Test Complete')

    def downloadAPK(self,numTotal):
        self.printLog('DownloadAPK Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.browser/.BrowserActivity')
            time.sleep(2)
            self.device.touch(345,147,MonkeyDevice.DOWN_AND_UP)
            self.device.type('http://192.168.10.101:8080/1.apk')
            #self.easyDevice.type(By.id('id/url'), 'http://192.168.1.56:8080/1.apk')
            time.sleep(2)
            self.device.touch(945,443,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
	    self.device.startActivity(component='com.android.providers.downloads.ui/.DownloadList')
            time.sleep(30)
            self.device.touch(420,293,MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.touch(641,535,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(641,535,MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            self.device.touch(641,535,MonkeyDevice.DOWN_AND_UP)
            time.sleep(20)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(2)
	    adbCommand = 'adb -s ' + self.sn + ' uninstall com.tencent.qqmusic'
            os.system(adbCommand)
            time.sleep(1)
	    adbCommandRM = 'adb -s ' + self.sn + ' shell rm /mnt/sdcard/download/*.apk'
            os.system(adbCommandRM)
            content = 'DownloadAPK Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            numTotal = numTotal - 1
        else:
            self.printLog('DownloadAPK Test Complete')

    def voiceDialer(self,numTotal):
        self.printLog('VoiceDialer Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.voicedialer/.VoiceDialerActivity')
            time.sleep(2)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            content = 'VoiceDialer Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(1)
            numTotal = numTotal - 1
        else:
            self.printLog('VoiceDialer Test Complete')

    def deerHunt(self,numTotal):
        self.printLog('DeerHunt Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.glu.deerhunt2/com.glu.plugins.glucn.AGlucnUnityLauncher.GlucnActivity')
            time.sleep(60)
            self.device.press('KEYCODE_HOME', MonkeyDevice.DOWN_AND_UP)
            content = 'DeerHunt Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1;
            time.sleep(2)
            numTotal = numTotal - 1
        else:
            self.printLog('DeerHunt Test Complete')

    def explorer(self,numTotal):
        self.printLog('Explorer Test Start')
        numCurrent = 1
        while numTotal > 0:
            self.device.startActivity(component='com.android.rk/.RockExplorer')
            time.sleep(5)
	    adbCommandCP = 'adb -s ' + self.sn + ' shell cp /mnt/sdcard/file.zip /mnt/sdcard/newfile.zip'
            os.system(adbCommandCP)
            time.sleep(1)
	    adbCommandRM = 'adb -s ' + self.sn + ' shell rm /mnt/sdcard/newfile.zip'
            os.system(adbCommandRM)
            time.sleep(1)
            self.device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
            time.sleep(1)
            content = 'Explorer Test ' + str(numCurrent)
            self.printLog(content)
            numCurrent = numCurrent + 1
            numTotal = numTotal - 1
        else:
            self.printLog('Explorer Test Complete')

class TestLancher:
    sn = ''
    def __init__(self,sn):
	self.sn = sn
		
    def test(self,num):
        tm = TestMoudle(self.sn)
        tm.printLog('Test Start')
        numCurrent = 1
        while num > 0:
            #tm.soundRecorder(2)
            tm.dvd(3)
            tm.radio(3)
            #tm.bt(3)
            tm.wifi(3)
            tm.navigation(3)
            tm.keylearning(1)
            tm.equalizer(1)
            #tm.videostudio(1)
            tm.calculator(2)
            tm.calender(1)
            tm.clock(2)
            #tm.Apkinstaller(3)
            tm.Browser(3)
            tm.ES(3)
            tm.FishGame(3)
            tm.Gallery3d(3)
            tm.Iceworld(3)
            tm.Quicksearchbox(1)
            tm.Smart(3)
            tm.Videoout(1)
            tm.Browser1M(3)            
            tm.Browser50M(3)
            tm.Music(3)
            tm.Picture(3)
            tm.Video(3)
            tm.Cheyooh(3)
            tm.Dazhihui(3)
            tm.Dianping(3)
            tm.musicplayer(3)
            tm.WangYi(3)
            tm.Oupeng(3)
            tm.tingshu(3)
            tm.VedioPlayer(3)
            tm.Fruit(3)
            tm.sendEmail(1)
            tm.checkEmail(1)
            tm.contact(1)
            #tm.btCall(100)
            #tm.btMusic(100)
            tm.Weixin(3)
            #tm.downloadAPK(3)
            #tm.voiceDialer(3)
            tm.deerHunt(3)
            tm.explorer(3)
            content = 'Test ' + str(numCurrent)
            tm.printLog(content)
            tm.printToFile('--------------------------------')
            print '-----------------------------------------------'
            numCurrent = numCurrent + 1
            num = num - 1
        else:
            tm.printLog('Test Complete')

tl = TestLancher('V8GCU6JBJL')
tl.test(10000)
